﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using GalaSoft.MvvmLight.Messaging;
using ViewModel.Rss;


namespace EPIClientRssWP7
{
    public partial class RemoveRssView : PhoneApplicationPage
    {
        public RemoveRssView()
        {
            InitializeComponent();
            Loaded += (obj, arg) =>
                {
                    Messenger.Default.Register<string>(this, "AnswerRemoveRss", (str) => 
                        {
                            if (NavigationService.CanGoBack)
                                NavigationService.GoBack();
                        });

                         Messenger.Default.Register<string>(this, "ErrorSaveRss", (str) => 
                        {
                            if (NavigationService.CanGoBack)
                                NavigationService.GoBack();
                        });

                };
        }

        private void click_save(object sender, System.EventArgs e)
        {
            if (!(this.DataContext is RemoveRssViewModel))
                return;
            var vm = this.DataContext as RemoveRssViewModel;
            vm.SelectedFeeds = this.ListBoxCheckBox.CheckedItemsSource;
            if (vm.CanExecuteRemoveFeeds() == true)
                vm.ExecuteRemoveFeeds();

        }

        private void click_cancel(object sender, System.EventArgs e)
        {
            if (NavigationService.CanGoBack)
               NavigationService.GoBack();
        }

   
    }
}
